﻿using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace Oddo.Concept.Crm.Common.Communication.Http
{
    public class CompressionHandler : DelegatingHandler
    {

        protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            return base.SendAsync(request, cancellationToken)
                        .ContinueWith(resp =>
                        {
                            resp.Result.Content = new CompressedContent(resp.Result.Content);
                            return resp.Result;
                        });

        }
    }
}